package edu.neu.ecommerceplatform.controller;

import edu.neu.ecommerceplatform.dto.LoginRequest;
import edu.neu.ecommerceplatform.dto.LoginResponse;
import edu.neu.ecommerceplatform.service.AuthService;
import jakarta.validation.Valid;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/api/auth")
public class AuthController {

    private final AuthService authService;

    @Autowired
    public AuthController(AuthService authService) {
        this.authService = authService;
    }

    @PostMapping("/login-by-phone")
    public ResponseEntity<LoginResponse> loginByPhone(@Valid @RequestBody LoginRequest loginRequest) {
        LoginResponse loginResponse = authService.loginByPhone(loginRequest);
        return ResponseEntity.ok(loginResponse);
    }
} 